home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 April
/
EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso
/
earcd
/
utilgfx
/
raylab.lha
/
RayLab
/
source
/
tga.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-17
|
2KB
|
78 lines
/*
name: tga.c
Targa 24-bit color picture support
----------------------------------
These routines enables image output in 24-bit targa format.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defs.h"
#include "tga.h"
#include "extern.h"
void WriteTgaHeader(FILE *f,long width, long height)
{
long i;
char tga_header[18];
for(i=0;i<18;i++) { tga_header[i]=(char) 0; } /* Init header (all entries = 0) */
tga_header[2]=(char) 2;
tga_header[12]=(char) (width&0xff);
tga_header[13]=(char) (width>>8);
tga_header[14]=(char) (height&0xff);
tga_header[15]=(char) (height>>8);
tga_header[16]=(char) 24;
tga_header[17]=(char) 0x20; /* Make picture appear "right" */
/* (upper left corner = first byte in body) */
for(i=0;i<18;i++) { fputc(tga_header[i],f); } /* Write header to file */
}
void ReadTgaHeader(FILE *f, long *width, long *height)
{
long i, temp;
for(i=1;i<=12;i++) { temp=fgetc(f); }
temp=fgetc(f); temp+=(fgetc(f)<<8); memcpy(width,&temp,(size_t) sizeof(temp));
temp=fgetc(f); temp+=(fgetc(f)<<8); memcpy(height,&temp,(size_t) sizeof(temp));
(void) fgetc(f); /* Skip information about image-depth... */
(void) fgetc(f); /* ...and about "mirroring" the picture... */
/* May add full support later. */
}
void WriteTgaPixle(FILE *f, char r, char g, char b)
{
fputc((char) b,f); fputc((char) g,f); fputc((char) r,f);
}
void ReadTgaPixle(FILE *f, int *r, int *g, int *b)
{
*b=fgetc(f); *g=fgetc(f); *r=fgetc(f);
}
void WriteTgaLine(FILE *f, long width)
{
long i;
unsigned char col;
for(i=0;i<width;i++) {
col=pixlearray[(i*3)+2]; /* Switch r<->b (in tga files the */
pixlearray[(i*3)+2]=pixlearray[(i*3)+0]; /* color comes as b,g,r) */
pixlearray[(i*3)+0]=col;
}
(void) fwrite(pixlearray,sizeof(unsigned char),(size_t)width*3,f);
}